/*
 * MouseExitListener.java
 *
 * Created on 28.11.2007, 0:05:55
 *
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.possoft.client.chess.gui.components;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import cz.possoft.client.chess.gui.panel.ChessPanel;
import cz.possoft.client.utils.PanelHolderUtils;
import cz.possoft.serializable.generic.Location;

/**
 *
 * @author mara
 */
public class MouseExitListener extends MouseAdapter {

    // nastava pokud mysi vyjedu z prostoru sachovnice
   
    public void mouseExited(MouseEvent me) {
    	if (!(PanelHolderUtils.getCurrentGamePanel() instanceof ChessPanel)) {
    		return;
    	}
    	ChessPanel chessPanel = (ChessPanel)PanelHolderUtils.getCurrentGamePanel();
        if (chessPanel.getGame().isActive()) {
            Location location = new Location(-1, -1);
            if (chessPanel.getGameState() < 3) {
            	chessPanel.updateRingFigurkaAndRepaint(location);
            }
        }
    }

    
    public void mousePressed(MouseEvent me) {
    	if (!(PanelHolderUtils.getCurrentGamePanel() instanceof ChessPanel)) {
    		return;
    	}    	
    	ChessPanel chessPanel = (ChessPanel)PanelHolderUtils.getCurrentGamePanel();
        if (chessPanel.getGame().isActive()) {
            Location location = ChessMouseMotionListener.getMouseLocation(me);
            if (chessPanel.getGameState() < 3) {
            	chessPanel.selectFigurkaForPlay(location);                
            } 
            else if ((chessPanel.getGameState() == 3) || (chessPanel.getGameState() == 4)) {
                // TODO - oddelani tohoto radku. Tim zamezime tomu, aby si hrac
                // mohl odoznacit figurku, kterou jiz oznacil pro tah.
            	chessPanel.deselectFigurkaSelectedForPlay(location);
            	chessPanel.play(location);
            }
        }
    }

}
